package com.itheima.d2_Stream_Api;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * Stream Api:
 *              1.filter
 *              2.forEach
 *              3.count
 *              4.limit 限制元素的数量最大值
 *              5.skip
 */
public class demo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三丰");
        list.add("张无忌");
        list.add("周芷若");
        list.add("赵敏");
        list.add("张天宝");
        //1 2
        //list.stream().filter(s -> s.startsWith("张")).forEach(s -> System.out.println(s));
        //3.count
        long size = list.stream().filter(s -> s.length()<3).count();
        //System.out.println(size);

        //4.limit
        //list.stream().filter(s -> s.startsWith("张")).limit(2).forEach(s -> System.out.println(s));

        //5.skip
        list.stream().filter(s -> s.startsWith("张")).skip(2).forEach(s -> System.out.println(s));

        //6.map
        list.stream().map(s -> "重邮"+s).forEach(s -> System.out.println(s));

        //7.将所有的名称加工成一个学生对象
        list.stream().map(s -> new Student(s)).forEach(student -> System.out.println(student));

        //8.合并流
        Stream<String> s1 = list.stream().filter(s -> s.startsWith("张"));
        Stream<String> s2 = Stream.of("java1","java2");
        Stream<Object> s3 = Stream.concat(s1,s2);
//        String[] ss = new String[3];
//        s2.map(s -> ss).forEach(ss);
        s3.forEach(s -> System.out.println(s));


    }
}
